package com.jugheadzhou.practice.newcoder;

import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String point = "\\.";
            String[] maskIpArr = in.nextLine().split(point);
            String[] ip1Arr = in.nextLine().split(point);
            String[] ip2Arr = in.nextLine().split(point);
            if (!checkMaskIp(maskIpArr)) {
                System.out.println("1");
                continue;
            }
            int result1 = 0;
            int result2 = 0;
            for (int i = 0; i < 4; i++) {
                Integer maskIpPart = Integer.valueOf(maskIpArr[i]);
                Integer ip1Part = Integer.valueOf(ip1Arr[i]);
                Integer ip2Part = Integer.valueOf(ip2Arr[i]);
                if (result1 == 0 && (check(ip1Part) || check(ip2Part))) {
                    result1 = 1;
                }
                if (result2 == 0 && !((maskIpPart & ip1Part) == (maskIpPart & ip2Part))) {
                    result2 = 2;
                }
            }
            if (result1 > 0) {
                System.out.println(result1);
            } else if (result2 > 0) {
                System.out.println(result2);
            } else {
                System.out.println(0);
            }

        }


    }
    private static boolean check(Integer ipPart) {
        return ipPart < 0 || ipPart > 255;
    }

    private static boolean checkMaskIp(String[] maskIpArr) {
        StringBuilder sb = new StringBuilder();
        for (String maskIpPart : maskIpArr) {
            int maskIpPartInt = Integer.parseInt(maskIpPart);
            if (check(maskIpPartInt)) {
                return false;
            }
            sb.append(String.format("%08d",
                    Integer.parseInt(Integer.toBinaryString(maskIpPartInt))));
        }
        String s = sb.toString();
        return s.lastIndexOf("1") < s.indexOf("0");
    }


}
